package xhwl.insurance.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.trello.rxlifecycle.components.RxActivity;

import java.util.ArrayList;
import java.util.List;

import xhwl.insurance.R;
import xhwl.insurance.customView.CircleImageView;
import xhwl.insurance.http.api.ForumDetailListApi;
import xhwl.insurance.http.bean.resp.ForumAllCommentResp;
import xhwl.insurance.http.bean.resp.ForumProductResp;
import xhwl.insurance.http.bean.resp2.HttpResp;
import xhwl.insurance.ui.ForumDetailNewActivity;
import xhwl.insurance.util.ImgTools;
import xhwl.insurance.view.ForumPictureView;
import xhwl.pulltorefresh.adapter.BaseAdapter;
import xhwl.pulltorefresh.adapter.ViewHolder;
import xhwl.retrofitrx.BaseApi;
import xhwl.retrofitrx.HttpManager;
import xhwl.retrofitrx.OnNextListener;

/**
 * Created by Administrator on 2017/10/12.
 */

public class AllCommentListAdapter extends BaseAdapter<ForumAllCommentResp> {
    private Context context;
    List<ForumAllCommentResp> commentList;
    OnItemClickLitener onItemClickLitener;
    private String post_id;
    private String name;

    public AllCommentListAdapter(Context context, List<ForumAllCommentResp> commentList) {
        super(context, R.layout.all_comment_item, commentList);
        this.context = context;
        this.commentList = commentList;
    }


    @Override
    public void convert(ViewHolder holder, final ForumAllCommentResp forumAllCommentResp) {
        final int pos = holder.getLayoutPosition();
        holder.setText(R.id.commentNickname, forumAllCommentResp.getREPLY_NAME());//姓名
        holder.setText(R.id.commentItemTime, forumAllCommentResp.getREPLY_DATE());//时间
        holder.setText(R.id.commentItemContent, forumAllCommentResp.getREPLY_DETAILS());//评论内容

        final CircleImageView touxiang = (CircleImageView) holder.getView(R.id.commentItemImg);//头像
        ImgTools.getInstance().getImgFromNetByUrl(forumAllCommentResp.getREPLY_ICON(), touxiang, R.drawable.touxiang);

        final ForumPictureView forumPicView = (ForumPictureView) holder.getView(R.id.forumPicView);
        forumPicView.setData(forumAllCommentResp.getREPLY_ANNEX(), 3);

        holder.setText(R.id.forum_title, "回复我的:" + forumAllCommentResp.getPOST_TITLE());//评论帖子标题

        post_id = forumAllCommentResp.getPOST_ID();
        name = forumAllCommentResp.getPOST_TITLE();
        holder.setOnclickListener(R.id.ll_reply_all_comment, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //根据post_id请求到bean 然后跳转到详情页
                onItemClickLitener.onItemClick(pos-1);

            }
        });
    }

    public interface OnItemClickLitener {
        void onItemClick(int position);

    }

    public void setOnItemClickLitener(OnItemClickLitener onItemClickLitener) {
        this.onItemClickLitener = onItemClickLitener;
    }
}
